package com.git.bcs.common.bean;

import java.io.IOException;
import java.util.Properties;

import javax.annotation.Resource;

import org.beetl.core.resource.ClasspathResourceLoader;
import org.beetl.core.resource.WebAppResourceLoader;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternUtils;

import com.git.bcs.common.bean.properties.BeetlProperties;
import com.git.bcs.common.utils.Constants;


@Configuration
public class BeetlConf {
	
	 @Autowired 
	 BeetlProperties beetlProperties;
	

	/**
	 * beetl的配置
	 */
	@Bean(initMethod = "init")
	public BeetlGroupUtilConfiguration beetlConfiguration() {
		BeetlGroupUtilConfiguration beetlConfiguration = new BeetlGroupUtilConfiguration();
		beetlConfiguration
				.setResourceLoader(new ClasspathResourceLoader(BeetlConf.class.getClassLoader(), beetlProperties.getPrefix()));
		beetlConfiguration.setConfigProperties(beetlProperties.getProperties());
		return beetlConfiguration;
	}

	/**
	 * beetl的视图解析器
	 */
	@Bean
	public BeetlSpringViewResolver beetlViewResolver() {
		BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
		beetlSpringViewResolver.setConfig(beetlConfiguration());
		beetlSpringViewResolver.setContentType(Constants.CONTYPE_UTF8);
		beetlSpringViewResolver.setOrder(0);
		return beetlSpringViewResolver;
	}
}
